#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int N = 0;
	int M = 0;
	int i = 0;
	int j = 0;
	scanf("%d%d", &N, &M);
	int* arr = (int*)malloc(sizeof(int) * N * M);
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < M; j++)
		{
			scanf("%d", &arr[i * M + j]);
		}
	}
	//1 2 3
	//4 5 6 
	// 
	//123456  142536
	//012345  012345
	// 
	//1 4
	//2 5
	//3 6   N=2;M=3
	for (i = 0; i < M; i++)
	{
		for (j = 0; j < N; j++)
		{
			printf("%d ", arr[j * M + i]);
		}
		printf("\n");
	}
	free(arr);
	return 0;
}
